import Router from 'koa-router'
import { getAllUsers, getUserById } from '../model/index'

const router = Router()

router.get('/', async (ctx, next) => {
  ctx.body = {
    data: {
      userList: [
        {
          "username": "defore",
          "age": 24
        },
        {
          "username": "tom",
          "age": 14
        }
      ]
    }
  }
})

router.get('/users', async (ctx, next) => {
  await getAllUsers()
    .then((rows) => {
      const list = rows
      ctx.body = {
        data: {
          list
        }
      }
    })
    .catch(err => {
      ctx.body = {
        success: false,
        msg: err
      }
    })
})

export default router
